let hour_pointer = document.querySelector('.hour')
let minute_pointer = document.querySelector('.minute')
let second_pointer = document.querySelector('.second')
// 星期
let weeks = [
  {
    text:"周日",
    text_en:'Sunday',
    color:"#32141e",
    color_text:"卵石紫"
  },
  {
    text:"周一",
    text_en:"Monday",
    color:"#7a7374",
    color_text:"锌灰"
  },
  {
    text:"周二",
    text_en:"Tuesday",
    color:"#2486b9",
    color_text:"宝石蓝"
  },
  {
    text:"周三",
    text_en:"Wednesday",
    color:"#f97d1c",
    color_text:"橘橙"
  },
  {
    text:"周四",
    text_en:"Thursday",
    color:"#ee4866",
    color_text:"淡蕊香红"
  },
  {
    text:"周五",
    text_en:"Friday",
    color:"#d2b42c",
    color_text:"草黄"
  },
  {
    text:"周六",
    text_en:"Saturday",
    color:"#1ba784",
    color_text:"竹绿"
  },
]
function toggleTheme(e) {
  if (document.body.classList.contains('dark')) {
    document.body.classList.remove('dark')
    e.innerText = 'Toggle Dark'
  } else {
    document.body.classList.add('dark')
    e.innerText = 'Toggle Theme'
  }
}


function createdLine() {
  let wrap = document.querySelector('.line_wrap')
  let style_tag = document.getElementsByTagName('style')[0]
  let css = ''
  for (let i = 0; i < 60; i++) {
    css+= `.line_wrap .line:nth-child(${i+1}){transform:rotate(${i*6}deg)}`
    wrap.innerHTML+=`<li class='line'></li>`
  }

  style_tag.innerHTML+=css
}

createdLine()

// StackOverflow https://stackoverflow.com/questions/10756313/javascript-jquery-map-a-range-of-numbers-to-another-range-of-numbers
const scale = (num, in_min, in_max, out_min, out_max) => {
  return (num - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

function fillZero(num){
  return num < 10 ? `0${num}` : num
}


let cur_day = 0
let date_text = document.querySelector('.date_text')
let week_text = document.querySelector('.week')
let tips = document.querySelector('.tips')
// 下班时间
let off_duty_time = '18:30'
//下班时间 带年月日 
let off_duty = ''
function timePassage() {
  let date = new Date()
  let now_ms = date.getTime() // 现在的时间戳
  let year = date.getFullYear() // 年份
  let month = date.getMonth() + 1  // 月份
  let week = date.getDay() // 星期几
  let day = date.getDate() // 日份
  let hours = date.getHours() // 小时
  let minute = date.getMinutes() // 分钟
  let second = date.getSeconds() // 秒
  hour_pointer.style.transform = `translate(-50%, -100%) rotate(${scale(hours, 0, 12, 0, 360)}deg)`
  minute_pointer.style.transform = `translate(-50%, -100%) rotate(${scale(minute, 0, 60, 0, 360)}deg)`
  second_pointer.style.transform = `translate(-50%, -100%) rotate(${scale(second, 0, 60, 0, 360)}deg)`
  if (day > cur_day) {
    cur_day = day
    date_text.innerText = `${year}年${fillZero(month)}月${fillZero(day)}日`
    week_text.innerText = `${weeks[week].text}`
    week_text.style.color = `${weeks[week].color}`
    off_duty = `${year}-${month}-${day} ${off_duty_time}`
  }

  if (week == 0 || week == weeks.length - 1) {
    tips.innerText = `今天是${weeks[week].text}哦,拒绝996,给自己放松一下,祝您生活愉快.`
  }else{
    let off_duty_ms = new Date(off_duty).getTime()

    if(now_ms >= off_duty_ms){
      tips.innerText = `收拾一下,下班吧,剩下的时间是自己的.`
      tips.style.color = `${weeks[week].color}`
    }else{
       // 距离下班的时间戳 --- 单位：秒
       let residue_time = (off_duty_ms - now_ms) / 1000
       let residue_hours = parseInt(residue_time / 60 / 60 % 24)
       let residue_minute = parseInt(residue_time / 60 % 60)
       let residue_second = parseInt(residue_time % 60)
       tips.innerText = `距离下班时间还有:${fillZero(residue_hours)}:${fillZero(residue_minute)}:${fillZero(residue_second)}`
    }
  }
 
}






timePassage()
setInterval(timePassage,1000)


